/* ApplicationForm verify anonymous function. By Leexw */
(function($){
	$.afvNotNull = function(target, msg){
		var result = $.trim(target).length > 0;
		return show(result, msg)
	};
	
	$.afvMinMaxLength = function(target, min, max, minMsg, maxMsg){
		var isLessMin = $.trim(target).length < min;
		var isGreaterMax = target.length > max;
		if(isLessMin) {
			return show(false, minMsg);
		} else if(isGreaterMax) {
			return show(false, maxMsg);
		}
		return show(true, "")
	};
	
	$.afvRealName = function (target) {
		var pattern = /^[\u4e00-\u9fa5]{2,8}$/;
		return afvPatternTest(target, pattern, '请填写真实姓名，长度为2～8的中文');
	};
	
	$.afvNation = function (target) {
		var pattern = /^[\u4e00-\u9fa5]{1,12}$/;
		return afvPatternTest(target, pattern, '请填写民族，长度为1～6的中文');
	};
	
	$.afvPhone = function (target) {
		var pattern = /^1[2-9][0-9]{9}$/;
		return afvPatternTest(target, pattern, '请填写正确的手机号码');
	};
	
	$.afvIdCard = function (target) {
		var pattern = /^[0-9xX]{16,18}$/;
		return afvPatternTest(target, pattern, '请填写正确的身份证号');
	};
	
	$.afvEmail = function (target) {
		var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/ ;
		return afvPatternTest(target, pattern, '请填写正确的电子邮箱');
	};
	
	$.afvPostcode = function (target) {
		var pattern = /^[0-9]{6}$/ ;
		return afvPatternTest(target, pattern, '请填写正确的邮政编码');
	};
	
    function afvPatternTest(target, pattern, message) {
    	var result = pattern.test($.trim(target));
    	return show(result, message);
	}
    
	function show(result, msg){
		if(!result) layer.msg(msg);
		return result;
	}
})(jQuery);